package com.view.use;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.view.status.R;
import com.view.status.StatusView;


public class MyStatusView extends StatusView {
    private onRetryClickLister retryClickLister;
    //网络错误视图
    private ImageView textViewMessage;
    private TextView text_error;

    //空视图
    private TextView tv_empty_text;
    private ImageView tv_empty_image;

    public MyStatusView(Context context) {
        super(context);
    }

    public static MyStatusView getInstance(Context context, String emptyText, onRetryClickLister retryClickLister) {
        MyStatusView statusView = new MyStatusView(context);
        statusView.setEmptyText(emptyText);
        statusView.setRetryClickLister(retryClickLister);
        return statusView;
    }

    @Override
    public int getRetryViewLayoutId() {
        return R.layout.my_status_retry;
    }

    @Override
    public int getLoadingViewLayoutId() {
        return R.layout.my_status_loading;
    }

    @Override
    public int getEmptyViewLayoutId() {
        return R.layout.my_stauts_empty;
    }

    @Override
    public int getSettingViewLayoutId() {
        return R.layout.my_status_setting;
    }


    /**
     * 网络加载失败视图
     */
    @Override
    public void initRetryView() {
        textViewMessage = mRetryView.findViewById(R.id.textViewMessage);
        text_error = mRetryView.findViewById(R.id.text_error);

        mRetryView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                retryClickLister.onRetryClick();
            }
        });
    }

    /**
     * 加载视图
     */
    @Override
    public void initLoadingView() {

    }

    /**
     * 空视图
     */
    @Override
    public void initEmptyView() {
        tv_empty_text = mEmptyView.findViewById(R.id.textViewMessage);
        tv_empty_image = mEmptyView.findViewById(R.id.empty_image);
    }

    /**
     * 设置视图
     */
    @Override
    public void initSettingView() {
        mSettingView.setOnClickListener(Util.getSettingNetwork());
    }

    /**
     * 网络错误视图
     *
     * @param retryClickLister 点击事件
     * @return
     */
    public MyStatusView setRetryClickLister(onRetryClickLister retryClickLister) {
        this.retryClickLister = retryClickLister;
        return this;
    }

    /**
     * 网络错误视图
     *
     * @param retryImage 图片修改
     * @return
     */
    public MyStatusView setRetryImage(int retryImage) {
        if (textViewMessage != null) {
            textViewMessage.setImageResource(retryImage);
        }
        return this;
    }

    /**
     * 网络错误视图
     *
     * @param errorText 文字修改
     * @return
     */
    public MyStatusView setRetryText(String errorText) {
        if (text_error != null) {
            text_error.setText(errorText);
        }
        return this;
    }


    /**
     * 空视图
     *
     * @param emptyText 文字修改
     * @return
     */
    public MyStatusView setEmptyText(String emptyText) {
        if (tv_empty_text != null) {
            tv_empty_text.setText(emptyText);
        }
        return this;
    }

    /**
     * 空视图
     *
     * @param emptyImage 图片修改
     * @return
     */
    public MyStatusView setEmptyImage(int emptyImage) {
        if (tv_empty_image != null) {
            tv_empty_image.setImageResource(emptyImage);
        }
        return this;
    }


    public interface onRetryClickLister {
        void onRetryClick();
    }
}
